'''
Created on Aug 19, 2009

@author: mkiyer
'''

def autolabel(ax, rects):
    # attach some text labels
    for rect in rects:
        height = rect.get_height()
        ax.text(rect.get_x()+rect.get_width()/2., 1.05*height, '%d'%int(height),
                ha='center', va='bottom')

def plot_bar(labels, bars, outfile, title="Bar Plot", 
             xlabel="X", ylabel="Y"):
    import numpy as np
    import matplotlib.pyplot as plt
    width=0.8
    fig = plt.figure()
    ax = fig.add_subplot(111)
    ind = np.arange(len(labels))    
    rects1 = ax.bar(ind, bars, width)
    ax.set_xticks(ind + width/2.0)
    #ax.set_xticklabels(labels, rotation=45, fontsize=8)
    ax.set_xticklabels(labels)
    fig.autofmt_xdate()
    autolabel(ax, rects1)
    plt.title(title)
    plt.xlabel(xlabel)
    plt.ylabel(ylabel)
    plt.grid(True)
    plt.savefig(outfile)
    plt.clf()